Skip to content

Add artificial_neural_network.py in neural_network #11858

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Closed

Add artificial_neural_network.py in neural_network #11858

wants to merge 13 commits into from

Conversation

AHuzail
Copy link

@AHuzail AHuzail commented Oct 7, 2024

Simple Artificial Neural Network (ANN) Implementation

Description:

This PR adds a basic implementation of a feedforward Artificial Neural Network (ANN) using Python and NumPy. The network consists of one hidden layer and uses Sigmoid activation, backpropagation with gradient descent, and Mean Squared Error (MSE) as the loss function. It demonstrates a solution to the XOR problem, commonly used in introductory neural network tutorials.

Key Features:

  • Feedforward neural network with 1 hidden layer.
  • Sigmoid activation function.
  • Gradient Descent optimizer for weight updates.
  • Mean Squared Error (MSE) loss function.
  • Example provided to solve the XOR problem.

Checklist:

  • Code follows the repository's contribution guidelines.
  • Tests have been added or updated.
  • Documentation has been updated (if applicable).
  • Code is well-documented with comments and descriptions.
  • [ X] Add an algorithm?

Checklist:

  • [ X] I have read CONTRIBUTING.md.
  • [ X] This pull request is all my own work -- I have not plagiarized.
  • [ X] I know that pull requests will not be merged if they fail the automated tests.
  • [ X] This PR only changes one algorithm file. To ease review, please open separate PRs for separate algorithms.
  • [ X] All new Python files are placed inside an existing directory.
  • [ X] All filenames are in all lowercase characters with no spaces or dashes.
  • [ X] All functions and variable names follow Python naming conventions.
  • [ X] All function parameters and return values are annotated with Python type hints.
  • [ X] All functions have doctests that pass the automated testing.
  • [ X] All new algorithms include at least one URL that points to Wikipedia or another similar explanation.

@AHuzail AHuzail marked this pull request as ready for review October 7, 2024 13:37
@algorithms-keeper algorithms-keeper bot added awaiting reviews This PR is ready to be reviewed require descriptive names This PR needs descriptive function and/or variable names require tests Tests [doctest/unittest/pytest] are required require type hints https://docs.python.org/3/library/typing.html labels Oct 7, 2024
Copy link

@algorithms-keeper algorithms-keeper bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Click here to look at the relevant links ⬇️

🔗 Relevant Links

Repository:

Python:

Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.

algorithms-keeper commands and options

algorithms-keeper actions can be triggered by commenting on this PR:

  • @algorithms-keeper review to trigger the checks for only added pull request files
  • @algorithms-keeper review-all to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.

NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.

"""Sigmoid activation function."""
return 1 / (1 + np.exp(-x))

def sigmoid_derivative(self, x):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file neural_network/artificial_neural_network.py, please provide doctest for the function sigmoid_derivative

Please provide return type hint for the function: sigmoid_derivative. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide descriptive name for the parameter: x

Please provide type hint for the parameter: x

"""Derivative of the sigmoid function."""
return x * (1 - x)

def feedforward(self, x):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file neural_network/artificial_neural_network.py, please provide doctest for the function feedforward

Please provide return type hint for the function: feedforward. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide descriptive name for the parameter: x

Please provide type hint for the parameter: x

self.final_output = self.sigmoid(self.final_input)
return self.final_output

def backpropagation(self, x, y, output):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As there is no test file in this pull request nor any test function or class in the file neural_network/artificial_neural_network.py, please provide doctest for the function backpropagation

Please provide return type hint for the function: backpropagation. If the function does not return a value, please provide the type hint as: def function() -> None:

Please provide descriptive name for the parameter: x

Please provide type hint for the parameter: x

Please provide descriptive name for the parameter: y

Please provide type hint for the parameter: y

Please provide type hint for the parameter: output

@AHuzail AHuzail marked this pull request as draft October 7, 2024 13:40
@AHuzail AHuzail closed this Oct 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting reviews This PR is ready to be reviewed require descriptive names This PR needs descriptive function and/or variable names require tests Tests [doctest/unittest/pytest] are required require type hints https://docs.python.org/3/library/typing.html
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant